package com.zx.test;

import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import com.zx.domain.requestUtils;
import com.zx.service.wxService;
import com.zx.wx.MenuItem;
import com.zx.wx.utils.BaseUtils;
import com.zx.wx.utils.MediaUtils;
import com.zx.wx.utils.MenuUtils;
import com.zx.wx.utils.OAuthUtils;
import com.zx.wx.utils.UserUtils;
import com.zx.wx.wxInterface.Base;
import com.zx.wx.wxInterface.Request;

@RunWith(SpringJUnit4ClassRunner.class)  
@ContextConfiguration(locations = {"classpath:/applicationContext.xml"})  
public class wxtest {
	@Autowired
	private wxService service;
	@Autowired
	private Base b;
	
	@Autowired Request request;
	
//	@Test
	public void test(){
		Map<String,Object> a=service.getAccess_token("wxc408c0125834275f", "d0dee76c226c661336a7a9baf4707166");
		System.out.println(a);
	}
	
	public void get(){
		service.setAccess_token("111","wxc408c0125834275f", "d0dee76c226c661336a7a9baf4707166");
	}

	public void getAccess_token(){
		String result=BaseUtils.getAccess_token("wxc408c0125834275f", "d0dee76c226c661336a7a9baf4707166", b, new requestUtils());
		System.out.println(result);
	}
//	@Test
	public void uploadMaterialTest(){
		String access_token="xi1FF9BfNvadsRbbAX1oi_kRI1FCU7FIzwQOpbBVZPQ_y7LRcMnxqN-pUZFFnEvSvq_dXAnrPYkNiThdEEuTswxEJZR6JxPSm8wFyHbance8-PG8dQAM5hkWU2Kptk-ePXIiABAJRC";
		String type="image";
		String filePath="D:321.png";
		File file=new File(filePath);
		System.out.println("是否存在："+file.exists());
		String result=MediaUtils.uploadMaterial(access_token, type, filePath, request);
		System.out.println(result);
	}
//	@Test
	public void uploadMpnews(){ //图文消息测试类
		String access_token="d9IjEj9exgm89R7pDYYhY48iQGjypThdg5UtJ1cIl_ANQJ5K5gSj0p55QarLhzn2TALaex79y_Ln6ziPKUA_HdTuppPGbWQDzarxqQnNsrCYDGVWUwCHd2Spny5uAAttAPVaABAETZ";
		List<String> articleList=new ArrayList<>();
		String article=MediaUtils.getArticle("图文消息1", "Udm38biA4y-1iF0RpaZwPZaUfr4tNueIwoZTl5avylo", "朱笑","摘要", "1", "图文消息消息体", "http://zhuzhuonlyone.6655.la/cms/wx/accessToken.zx");
		articleList.add(article);
		MediaUtils.uploadMpnews(access_token, articleList, request);
	}
//	@Test
	public void uploadMpnewsImage(){
		String access_token="d9IjEj9exgm89R7pDYYhY48iQGjypThdg5UtJ1cIl_ANQJ5K5gSj0p55QarLhzn2TALaex79y_Ln6ziPKUA_HdTuppPGbWQDzarxqQnNsrCYDGVWUwCHd2Spny5uAAttAPVaABAETZ";
		String filePath="D:321.png";
		System.out.println(MediaUtils.uploadMpnewsImage(access_token, filePath, request));
	}
//	@Test
	public void getPermanentMaterial(){//获取永久素材
		String access_token="d9IjEj9exgm89R7pDYYhY48iQGjypThdg5UtJ1cIl_ANQJ5K5gSj0p55QarLhzn2TALaex79y_Ln6ziPKUA_HdTuppPGbWQDzarxqQnNsrCYDGVWUwCHd2Spny5uAAttAPVaABAETZ";
		String media_id="Udm38biA4y-1iF0RpaZwPTnuh9uDRDfAnXxmlSS9uFg";
		System.out.println(MediaUtils.getPermanentMaterial(access_token,media_id, request));
	}
//	@Test
	public void updateMpnews(){//修改永久素材
		String access_token="d9IjEj9exgm89R7pDYYhY48iQGjypThdg5UtJ1cIl_ANQJ5K5gSj0p55QarLhzn2TALaex79y_Ln6ziPKUA_HdTuppPGbWQDzarxqQnNsrCYDGVWUwCHd2Spny5uAAttAPVaABAETZ";
		String media_id="Udm38biA4y-1iF0RpaZwPTnuh9uDRDfAnXxmlSS9uFg";
		String article=MediaUtils.getArticle("图文消息0", "Udm38biA4y-1iF0RpaZwPZaUfr4tNueIwoZTl5avylo", "朱笑","摘要", "1", "图文消息消息体", "http://zhuzhuonlyone.6655.la/cms/wx/accessToken.zx");
		System.out.println(MediaUtils.updateMpnews(access_token, media_id, "0", article , request));
	}
//	@Test
	public void getMaterialCount(){//获取素材总数
		String access_token="d9IjEj9exgm89R7pDYYhY48iQGjypThdg5UtJ1cIl_ANQJ5K5gSj0p55QarLhzn2TALaex79y_Ln6ziPKUA_HdTuppPGbWQDzarxqQnNsrCYDGVWUwCHd2Spny5uAAttAPVaABAETZ";
		System.out.println(MediaUtils.getMaterialCount(access_token, request));
	}
//	@Test
	public void getMaterialList(){//获取素材列表
		String type="image";
		String offset="0";
		String count="20";
		String access_token="akiTKkaafQJZJUD_-MiYbTdIhyNDJBme-a30m9EUvNZfuUaiRMwGTDQBxkHOCMLI_haxXXy7WukgGv2KIIoU0JWgCTvfVC_WMMNzLjQSBgJI2j0Ld8jBoamCUVzR77YBJMCjABADGW";
//		{"item":[{"media_id":"Udm38biA4y-1iF0RpaZwPZaUfr4tNueIwoZTl5avylo","name":"321.png","update_time":1472710257,"url":"http:\/\/mmbiz.qpic.cn\/mmbiz_png\/HWibpdyJ33nj9b1z0YzCphdwtkhhsM7iaibsL56nGEcp0vZHcqUv1v0xNoGbhwenzHRmGx1I0iaUenia4lRLLUibiaQibg\/0?wx_fmt=png"}],"total_count":1,"item_count":1}
		System.out.println(MediaUtils.getMaterialList(access_token,type,offset,count, request));
	}
//	@Test
	public void createGroup(){//创建分组
		String access_token="akiTKkaafQJZJUD_-MiYbTdIhyNDJBme-a30m9EUvNZfuUaiRMwGTDQBxkHOCMLI_haxXXy7WukgGv2KIIoU0JWgCTvfVC_WMMNzLjQSBgJI2j0Ld8jBoamCUVzR77YBJMCjABADGW";
		String groupName="测试一号";
		System.out.println(UserUtils.groupManageUtils.createGroup(access_token, groupName, request));
	}
//	@Test
	public void queryAllGroup(){//创建分组
		String access_token="akiTKkaafQJZJUD_-MiYbTdIhyNDJBme-a30m9EUvNZfuUaiRMwGTDQBxkHOCMLI_haxXXy7WukgGv2KIIoU0JWgCTvfVC_WMMNzLjQSBgJI2j0Ld8jBoamCUVzR77YBJMCjABADGW";
		System.out.println(UserUtils.groupManageUtils.queryAllGroup(access_token, request));
	}
//	@Test
	public void queryUserGroup(){//查询用户分组
		String access_token="akiTKkaafQJZJUD_-MiYbTdIhyNDJBme-a30m9EUvNZfuUaiRMwGTDQBxkHOCMLI_haxXXy7WukgGv2KIIoU0JWgCTvfVC_WMMNzLjQSBgJI2j0Ld8jBoamCUVzR77YBJMCjABADGW";
		System.out.println(UserUtils.groupManageUtils.queryUserGroup(access_token,"okYfGv9twGuc-_i1aiJ4lgi5_REc", request));
	}
//	@Test
	public void changeGroupName(){//查询用户分组
		String access_token="akiTKkaafQJZJUD_-MiYbTdIhyNDJBme-a30m9EUvNZfuUaiRMwGTDQBxkHOCMLI_haxXXy7WukgGv2KIIoU0JWgCTvfVC_WMMNzLjQSBgJI2j0Ld8jBoamCUVzR77YBJMCjABADGW";
		System.out.println(UserUtils.groupManageUtils.changeGroupName(access_token,"1","测试分组", request));
	}
//	@Test
	public void testmune(){
		String access_token="2VKxULwof-4dde9_911YrYepB9pjY7oOdAEOFYzRDJUzu-6hzSlMXhjlQ9cfpFQ8OGpW_FJbyyZWRaJiWh0l6fdpE7FNbItRQr6Vv9HSwdMUg4cl95ajRFPufuuSm-78AWEjABAOKS";
		List<String> ButtonItem1=new ArrayList<String>();
		ButtonItem1.add(MenuItem.view.getContent("accessToken", "http://211.149.202.130/cms/wx/accessToken.zx"));
		ButtonItem1.add(MenuItem.view.getContent("jssdk", "http://211.149.202.130/cms/jssdk.html"));
		String subButton1=MenuItem.sub_button.getContent("关键参数", ButtonItem1.toString()); //第一个
		List<String> ButtonItem2=new ArrayList<String>();
		ButtonItem2.add(MenuItem.view.getContent("隐式授权", "http://211.149.202.130/cms/snsapi_base.html"));
		ButtonItem2.add(MenuItem.view.getContent("显式授权", "http://211.149.202.130/cms/snsapi_userinfo.html"));
		String subButton2=MenuItem.sub_button.getContent("授权页面", ButtonItem2.toString()); //第一个
		List<String> button=new ArrayList<String>();
		button.add(subButton1);
		button.add(subButton2);
		String content=MenuItem.button.getContent(button.toString());
		System.out.println(content);
		System.out.println(MenuUtils.createMenu(access_token, content, request));
	}
	@Test
	public void getuserInfo(){
		String code="001rxyK71gzCaX1tmXJ71vWAK71rxyK9";
		String appID="wxc408c0125834275f";
		String appsecret="d0dee76c226c661336a7a9baf4707166";
		System.out.println(OAuthUtils.codeToOpenId(appID, appsecret, code, request));
	}
}
